#------------------------------------------------------------------------------
#Environment.py
#Created on 22.06.2009
#@author: Akuryou
#@contact: akuryou@l2si.de
#@version: 1.00
#------------------------------------------------------------------------------

import random

from direct.showbase import DirectObject
from pandac.PandaModules import *

class Environment(DirectObject.DirectObject):
    """Class which will add sky and sunlight"""

    def __init__(self):
        # add light
        dlight = DirectionalLight('dlight')
        dlight.setColor(VBase4(1, 1, 1, 1))
        dlnp = render.attachNewNode(dlight)
        dlnp.setHpr(318, 216, 0)
        
        alight = AmbientLight('alight')
        alight.setColor(VBase4(0.5, 0.5, 0.5, 1))
        alnp = render.attachNewNode(alight)
        
        render.setLight(alnp)
        render.setLight(dlnp)
        
        # add sky             
        self.sky = loader.loadModel("sky")
        self.sky.reparentTo(base.camera)
        self.sky.setEffect(CompassEffect.make(render)) 
        self.sky.setScale(50)
        self.sky.setDepthWrite(0)
        self.sky.setBin('background', 0) 
        self.sky.setShaderOff()
        self.sky.setLightOff()
        
        # add the task for sky updates
        taskMgr.add(self.updateSky, 'updateSky-task')
        
    def updateSky(self, task):
        """task which keeps the sky around the camera"""
        pos = base.camera.getPos(render)
        return task.cont